#include<bits/stdc++.h>
using namespace std;
int t,n,m,l,tv;
long long ans=0;
int d[100010],v[100010],a[100010],p[100010];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        ans=0;
        cin>>n>>m>>l>>tv;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];

        }
        for(int i=1;i<=n;i++){
            int su=v[i];
            if(a[i]==0){
                if(su>tv){
                    if(p[m]>=d[i]){
                        ans++;
                    }
                }
            }

        }
        if(ans!=0){
            cout<<ans<<" "<<m-1<<endl;
        }
        else if(ans==0){
            cout<<ans<<" "<<m<<endl;
        }
    }
    return 0;
}
